package com.sto.stoapp.listener;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.log.ExceptionLog;

/**
 * 抽象点击监听事件
 * 
 * @author mgf
 * 
 */
public abstract class StoOnClickListener implements OnClickListener {
	private Activity activity;

	/**
	 * MHOnClickListener
	 * 
	 * @param activity
	 *            tag
	 */
	public StoOnClickListener(Activity activity) {
		this.activity = activity;
	}

	/**
	 * onClick
	 * 
	 * @param view
	 *            tag
	 */
	@Override
	public void onClick(View view) {
		try {
			mHonClick(view);
		} catch (Throwable exception) {
			new AlertDialog.Builder(activity)
					.setMessage(exception.toString())
					.setPositiveButton(R.string.confirm,
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface arg0,
										int arg1) {
									arg0.dismiss();
								}
							}).setCancelable(false).show();
			ExceptionLog.writeLog("StoOnClickListener", exception.getMessage());
		}
	}

	/**
	 * mHonClick
	 * 
	 * @param view
	 *            tag
	 */
	public abstract void mHonClick(View view);
}
